﻿namespace wToggl
{
    using Windows.Security.Cryptography.DataProtection;
    using Windows.Storage;
    using Windows.Security.Cryptography.DataProtection;

    using wToggle.Platform.Interfaces;

    internal class PhoneSettings : IApplicationSettings
    {
        public string Username
        {
            get
            {
                var username = ApplicationData.Current.LocalSettings.Values["username"] as string;
                return username;
            }
            set
            {
                ApplicationData.Current.LocalSettings.Values["username"] = value;
            }
        }

        public string Password
        {
            get
            {
                return ApplicationData.Current.LocalSettings.Values["password"] as string;
            }
            set
            {
                ApplicationData.Current.LocalSettings.Values["password"] = value;
            }
        }

        public string ApiToken
        {
            get
            {
                return ApplicationData.Current.LocalSettings.Values["token"] as string;
            }
            set
            {
                ApplicationData.Current.LocalSettings.Values["token"] = value;
            }
        }

        public ulong? LastWorkspace
        {
            get
            {
                return ApplicationData.Current.LocalSettings.Values["lastWs"] as ulong?;
            }
            set
            {
                ApplicationData.Current.LocalSettings.Values["lastWs"] = value;
            }
        }

        public void ClearLogin()
        {
            this.Password = null;
            this.Username = null;
            this.ApiToken = null;
        }

        public bool HasLogin()
        {
            return !string.IsNullOrEmpty(this.Username) && !string.IsNullOrEmpty(this.Password);
        }
    }
}
